package com.bitdf.txing.seckill.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bitdf.txing.common.to.SkuReductionTo;
import com.bitdf.txing.common.utils.R;
import com.bitdf.txing.seckill.entity.SkuFullReductionEntity;
import com.bitdf.txing.seckill.service.SkuFullReductionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;



/**
 * 商品满减信息
 *
 * @author lizhiwei
 * @email sunlightcs@gmail.com
 * @date 2022-05-16 21:36:42
 */
@Slf4j
@RestController
@RequestMapping("${txing.request.path.seckill}/coupon/skufullreduction")
public class SkuFullReductionController {
    @Autowired
    private SkuFullReductionService skuFullReductionService;

    /**
     * 在创建商品保存sku的满减、满打折信息
     * @param skuReductionTo
     * @return
     */
    @PostMapping("/skuto/save")
    @SaCheckLogin
    @SaCheckPermission("mall:seckill:sku:full:reduction:add")
    public R saveinfo(@RequestBody SkuReductionTo skuReductionTo){
        skuFullReductionService.saveSkuReduction(skuReductionTo);
        log.info("满减信息保存成功");
        return R.ok();
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SkuFullReductionEntity skuFullReduction = skuFullReductionService.getById(id);

        return R.ok().put("skuFullReduction", skuFullReduction);
    }

    /**
     * 保存
     */
    @SaCheckLogin
    @SaCheckPermission("mall:seckill:sku:full:reduction:add")
    @RequestMapping("/save")
    public R save(@RequestBody SkuFullReductionEntity skuFullReduction){
		skuFullReductionService.save(skuFullReduction);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @SaCheckLogin
    @SaCheckPermission("mall:seckill:sku:full:reduction:update")
    public R update(@RequestBody SkuFullReductionEntity skuFullReduction){
		skuFullReductionService.updateById(skuFullReduction);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @SaCheckLogin
    @SaCheckPermission("mall:seckill:sku:full:reduction:delete")
    public R delete(@RequestBody Long[] ids){
		skuFullReductionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
